package com.register.web;

import com.register.pojo.User;
import com.register.service.RegistorService;
import com.register.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

@RestController
@RequestMapping("/registor")
public class UserController
{
    @Autowired
    private RegistorService registorService;
    @Autowired
    private UserService userService;
    @RequestMapping("login")
    public void login(HttpServletResponse response,String username, String password){
        User user = userService.selectUser(username, password);
        if(user!=null) {
            String uuid = UUID.randomUUID().toString();
            registorService.setRedisUser(uuid,user);
            Cookie cookie = new Cookie("ticket", uuid);
            cookie.setMaxAge(600);
            response.addCookie(cookie);
        }
    }
}
